package com.hulk.dryad.manage.framework.websocket.server.user;

import cn.hutool.core.util.StrUtil;
import com.google.common.collect.Maps;

import java.util.*;

/**
 * 默认的用户存储
 *
 * @author hulk
 */
public class DefaultWsUserStore implements IWsUserStore {
  /** 可能会堆满内存，尽量不要使用这种方式 */

  private static final HashMap<String, LinkedHashSet<String>> DATA = Maps.newHashMap();

	@Override
	public List<String> listAll(String tenant) {
		return new ArrayList<>(DATA.get(tenant));
	}

	@Override
	public boolean has(String userInfo) {
		String tenant = pickTenant(userInfo);
		Set<String> info = 	DATA.get(tenant);
		String  key = tenant+ StrUtil.COLON+ STORE_KEY;
		return info.contains(key);
	}

	@Override
	public void put(String userInfo) {
		String tenant = pickTenant(userInfo);
		Set<String> info = 	DATA.get(tenant);
		String  key = tenant+ StrUtil.COLON+ STORE_KEY;
		info.add(key);
	}

	@Override
	public void remove(String userInfo) {
		String tenant = pickTenant(userInfo);
		Set<String> info = 	DATA.get(tenant);
		String  key = tenant+ StrUtil.COLON+ STORE_KEY;
		info.remove(userInfo);
	}
}
